<template>
    <div class="body">
    <div class="texter"></div>
    <!-- <img
      src="../../assets/img/hong/title2.png"
      class="images"
      alt=""
    > -->
    <!-- 爆品好物 -->
    <div class="Boxed">
      <img
        src="../../assets/img/hong/three/title1@2x.png"
        alt=""
        class="imag"
      >
      <ul>
        <li
          v-for="item in atr"
          :key="item.goods_id"
          @click="nav(item)"
        >
          <div class="fiex">

          </div>
          <div class="wi">
            <img
              v-lazy="item.goods_img"
              :key="item.goods_img"
            >
          </div>
          <div class="text">
            {{item.goods_name}}
          </div>
          <div class="vip">
            <span>会员价</span>
            <div class="money">
              ¥
              <span>{{item.active_price}}</span>
            </div>
            <img
              src="../../assets/img/hong/three/gou.png"
              alt=""
              class="shopping"
            >
          </div>
        </li>
      </ul>
    </div>
    <!-- 为你推荐 -->
    <div class="fles">
      <img
        src="../../assets/img/hong/three/title2@2x.png"
        alt=""
        class="imag"
      >
      <div class="dev">
        <ul>
          <li
            v-for="item in atrdev"
            :key="item.goods_id"
            @click="nav(item)"
          >
            <img
              v-lazy="item.goods_img"
              :key="item.goods_img"
            >
            <div class="text">
              {{item.goods_name}}
            </div>
            <div class="money">
              ¥
              <span>{{item.active_price}}</span>
              <van-icon name="shopping-cart" />
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="add">
      <img
        src="../../assets/img/hong/three/title3@2x.png"
        alt=""
        class="imag"
      >
      <ul>
        <li
          v-for="item in list"
          :key="item.goods_id"
          @click="nav(item)"
        >
          <img
            class="img"
            v-lazy="item.goods_img"
            :key="item.goods_img"
          >
          <div class="text">
            {{item.goods_name}}
          </div>
          <div class="money">
            ¥
            <span>{{item.active_price}}</span>
          </div>
          <img
            src="../../assets/img/hong/three/gou.png"
            class="shopping"
            alt=""
          >
        </li>
      </ul>
    </div>

    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { index, Coupondev } from '@/api/index'
import { share } from '../../js/public'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
export default {
  // 组件名称
  name: '',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      list: [],
      atr: [],
      atrdev: [],
      system: getSystem(),
      btnFlag: false,
    }
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.create()
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    window.addEventListener('scroll', this.scrollToTop)
  },
  // 组件方法
  methods: {
    async create () {
      try {
        const res = await index({
          id: 147
        })
        console.log(res.data.data.types);
        this.atr = res.data.data.types[0].goods.slice(0, 3)
        this.atrdev = res.data.data.types[0].goods.slice(3, 90)
        this.list = res.data.data.types[1].goods
      } catch (err) {
        console.log('错误');
      }
    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
    // 跳转下载
    nav (item) {
      console.log(item.goods_id);
      // window.locaition.href = 'http://yuanfuda933.oss-cn-zhangjiakou.aliyuncs.com/yfdMall_1_v1.0.1.apk?squId=' + 'item.goods._id'
      window.location.href = 'yfd://yfdmall:8080/goodsDetail?spuId=' + item.goods_id
    },
    href (uri, blank = true) {
      const a = document.createElement('a')
      a.style.display = 'none'
      a.href = uri
      if (blank) a.setAttribute('target', '_blank')
      document.body.appendChild(a)
      a.click()
      setTimeout(t => {
        document.body.removeChild(a)
      }, 0)
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  background: #f6c566;
  margin: 0 auto;
  line-height: 1.5;
  font-family: Arial, Helvetica;
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }
  .add {
    width: 9.653333rem;
    margin: 0.133333rem auto;
    background: #ff9fe0;
    border-radius: 0.4rem;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    padding-top: 1.6rem;
    .imag {
      position: absolute;
      top: 0%;
      width: 100%;
      height: 3.573333rem;
    }
    ul {
      li {
        z-index: 99;
        float: left;
        width: 4.56rem;
        height: 6.64rem;
        border-radius: 0.166667rem;
        background: #ffffff;
        margin-bottom: 0.266667rem;
        margin-left: 0.186667rem;
        position: relative;
        .shopping {
          position: absolute;
          right: 6%;
          bottom: 4%;
          width: 0.8rem;
          height: 0.8rem;
        }
        .img {
          width: 3.493333rem;
          height: 3.173333rem;
          margin-top: 0.773333rem;
          margin-left: 0.506667rem;
        }
        .text {
          margin: 0.206667rem auto 0;
          width: 3.093333rem;
          height: 1.033333rem;
          font-weight: 600;
          font-size: 0.373333rem;
          color: #333333;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .money {
          margin-left: 0.646667rem;
          // width: 1.333333rem;
          // height: 0.426667rem;
          font-size: 0.373333rem;
          color: #ff301e;
          span {
            font-size: 0.613333rem;
          }
        }
      }
    }
  }
  .texter {
    width: 10rem;
    height: 13.493333rem;
    background: url("../../assets/img/hong/three/header@2x.png") no-repeat;
    background-size: contain;
  }
  .Boxed {
    width: 9.653333rem;
    height: 8.72rem;
    margin: 0.133333rem auto;
    background: #f1854a;
    border-radius: 0.4rem;
    position: relative;
    box-sizing: border-box;
    padding-top: 1.6rem;
    padding-right: 14px;
    .imag {
      position: absolute;
      top: 0%;
      width: 100%;
      height: 3.573333rem;
    }
    ul {
      li:nth-child(n + 2) .wi {
        margin-top: 0.346667rem;
        margin-left: 0.106667rem;
        width: 2.026667rem;
        height: 2.693333rem;
        background: #ffffff;
        border-radius: 0.4rem;
        overflow: hidden;
        img {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
      li:nth-child(n + 2) .text {
        position: absolute;
        top: 12%;
        right: 2%;
        width: 2.266667rem;
        font-weight: 600;
        font-size: 0.373333rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
      li:nth-child(n + 2) .vip {
        position: absolute;
        right: 6%;
        top: 43%;
        height: 1.866667rem;
        width: 2.266667rem;
        // margin-top: 0.266667rem;
        span {
          margin-left: 0.233333rem;
          width: 1.066667rem;
          height: 0.4rem;
          font-size: 0.266667rem;
          text-align: center;
          line-height: 0.4rem;
          background: #fc785c;
          color: #ffffff;
        }
        .money {
          margin-left: 0.16rem;
          font-size: 0.32rem;
          color: #fe3b2d;
          span {
            margin-left: 0;
            background: transparent;
            font-size: 0.48rem;
            color: #fe3b2d;
          }
        }
        .shopping {
          display: none;
          margin-left: 0.6rem;
          width: 0.72rem;
          height: 0.72rem;
        }
      }
      li:nth-child(1) .fiex {
        position: absolute;
        top: 0%;
        left: 6%;
        width: 1.093333rem;
        height: 1.28rem;
        background: url("../../assets/img/hong/three/2@2x.png") no-repeat;
        background-size: contain;
      }
      li:nth-child(2) .fiex {
        position: absolute;
        top: 0%;
        left: 0%;
        width: 2.133333rem;
        height: 0.533333rem;
        background: url("../../assets/img/hong/three/3@2x.png") no-repeat;
        background-size: contain;
      }
      li:nth-child(3) .fiex {
        position: absolute;
        top: 0%;
        left: 0%;
        width: 2.133333rem;
        height: 0.533333rem;
        background: url("../../assets/img/hong/three/4@2x.png") no-repeat;
        background-size: contain;
      }
      li {
        z-index: 99;
        float: right;
        border-radius: 0.4rem;
        background: -webkit-linear-gradient(top, #f9ba6a, #ffffff);
        width: 4.693333rem;
        height: 3.226667rem;
        margin-bottom: 0.186667rem;
        position: relative;
      }
      li:nth-child(1) {
        float: left;
        margin-left: 0.16rem;
        width: 4.48rem;
        height: 6.64rem;
        .wi {
          width: 4.106667rem;
          height: 3.68rem;
          background: #ffffff;
          border-radius: 0.4rem;
          margin: 0.533333rem auto 0;
          overflow: hidden;
          img {
            display: block;
            width: 3.106667rem;
            height: 3.106667rem;
            margin: 0.26rem auto 0;
            // border-radius: 0.4rem;
          }
        }
        .text {
          width: 3.92rem;
          margin: 0.133333rem auto;
          font-weight: 600;
          font-size: 0.373333rem;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .vip {
          margin-top: 0.266667rem;
          display: flex;
          span {
            margin-top: 0.16rem;
            margin-left: 0.233333rem;
            width: 1.066667rem;
            height: 0.4rem;
            font-size: 0.266667rem;
            text-align: center;
            line-height: 0.4rem;
            background: #fc785c;
            color: #ffffff;
          }
          .money {
            width: 2.133333rem;
            margin-top: 0.16rem;
            margin-left: 0.16rem;
            font-size: 0.32rem;
            color: #fe3b2d;
            span {
              margin-left: 0;
              background: transparent;
              font-size: 0.48rem;
              color: #fe3b2d;
            }
          }
          .shopping {
            width: 0.72rem;
            height: 0.72rem;
          }
        }
      }
    }
  }
  .fles {
    width: 9.653333rem;
    height: 5.653333rem;
    margin: 0.133333rem auto;
    background: #9acafa;
    border-radius: 0.4rem;
    position: relative;
    box-sizing: border-box;
    padding-top: 1.6rem;
    .imag {
      position: absolute;
      top: 0%;
      width: 100%;
      height: 3.053333rem;
    }
    .dev {
      display: flex;
      overflow-y: hidden;
      overflow-x: scroll;
      ul {
        display: flex;
        li {
          z-index: 99;
          margin-left: 0.16rem;
          width: 2.533333rem;
          height: 3.786667rem;
          background: #ffffff;
          border-radius: 0.266667rem;
          img {
            display: block;
            margin: 0.266667rem auto;
            width: 1.76rem;
            height: 1.76rem;
          }
          .text {
            width: 2.333333rem;
            margin: 0 auto;
            height: 0.96rem;
            font-size: 0.32rem;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
          }
          .money {
            margin-left: 0.16rem;
            font-size: 0.266667rem;
            color: #d6462c;
            span {
              font-size: 0.373333rem;
            }
            .van-icon {
              margin-left: 0.26rem;
            }
          }
        }
      }
    }
  }
  .images {
    width: 10rem;
    height: 1.173333rem;
    // margin-top: -1.333333rem;
  }
}
@keyframes mymove {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}
@-webkit-keyframes mymove /*Safari and Chrome*/ {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}
</style>
